﻿using Nova_DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Report_RepList : System.Web.UI.Page
{
    Nova_DAL.DbHelper access = new DbHelper();
    string strSQL = "";
    DbCommand cmd = null;
    DataSet ds = null;
    string strStockNo = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        
   
        try
        {
            strStockNo = Request["strStockNo"].ToString();
        }
        catch (Exception ex)
        {
        }
        if (!IsPostBack)
        {
            bind(strStockNo);
        }
    }


    protected void bind(string strStockNo)
    {
        //string WCode = Request.Cookies["WType"].Value;
        //strSQL = "Select  TBM.Mat_Name,TBM.Mat_Code,TDS.StockNo,TDS.Num,ISNULL(TDS.Act_Num,0) AS Act_Num,TDS.S01,TDS.S02,TDS.S04,TDS.PID from TDelStorage_List TDS LEFT JOIN TBase_Material TBM ON TDS.Mat_Code = TBM.Mat_Code Where TDS.StockNo = '" + strStockNo + "' and (TDS.TS02='" + WCode + "' or 'FSSC'='" + WCode + "')";
        strSQL = "SELECT StockNo,Mat_Name,Mat_Code,Mat_Num,Tray_ID,CDT FROM TPackage_Material Where StockNo = '" + strStockNo + "'";

        
        cmd = access.GetSqlStringCommond(strSQL);
        gv.DataSource = access.ExecuteDataSet(cmd);
        gv.DataBind();

        GroupRows(gv, 1);

    }


    /// <summary>
    /// 合并GridView中某列相同信息的行（单元格） 
    /// </summary>
    /// <param name="GridView1">GridView</param>
    /// <param name="cellNum">第几列</param>

    public static void GroupRows(GridView GridView1, int cellNum)
    {
        int i = 0, rowSpanNum = 1;
        while (i < GridView1.Rows.Count - 1)
        {
            GridViewRow gvr = GridView1.Rows[i];

            for (++i; i < GridView1.Rows.Count; i++)
            {
                GridViewRow gvrNext = GridView1.Rows[i];
                if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
                {
                    gvrNext.Cells[cellNum].Visible = false;
                    rowSpanNum++;
                }
                else
                {
                    gvr.Cells[cellNum].RowSpan = rowSpanNum;
                    rowSpanNum = 1;
                    break;
                }

                if (i == GridView1.Rows.Count - 1)
                {
                    gvr.Cells[cellNum].RowSpan = rowSpanNum;
                }
            }
        }
    }
}
